<?php
class Category_mo extends CI_Model {

	var $title   = '';
	var $content = '';
	var $date    = '';

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	function get_all_category($category_code, $depth)
	{
		if ($category_code = null)
		{
			$category_code = '0';
		}

		if ($depth = null)
		{
			$depth = 0;
		}

		$sql = 'SELECT ';
		$sql .=     'category_code, ';
		$sql .=     'category_name_pc, ';
		$sql .=     'category_name_mobile, ';
		$sql .=     'parent_category_code, ';
		$sql .=     'path, ';
		$sql .=     'depth, ';
		$sql .=     'display_order, ';
		$sql .=     'commodity_count_pc, ';
		$sql .=     'commodity_count_mobile, ';
		$sql .=     'last_related_count_datetime, ';
		$sql .=     'public_commodity_count_pc, ';
		$sql .=     'public_commodity_count_mobile, ';
		$sql .=     'last_public_count_datetime, ';
		$sql .=     'orm_rowid ';
		$sql .= 'FROM ';
		$sql .=     'category ';
		$sql .= 'WHERE ';
		$sql .=     'path like \'%' . $category_code . ':' . $depth . '%\' ';
		$sql .= 'ORDER BY ';
		$sql .=     'path ';

		return $this->db->query($sql)->result();
	}




	function get_last_ten_entries()
	{
		$query = $this->db->get('entries', 10);
		return $query->result();
	}

	function insert_entry()
	{
		$this->title   = $_POST['title']; // please read the below note
		$this->content = $_POST['content'];
		$this->date    = time();

		$this->db->insert('entries', $this);
	}

	function update_entry()
	{
		$this->title   = $_POST['title'];
		$this->content = $_POST['content'];
		$this->date    = time();

		$this->db->update('entries', $this, array('id' => $_POST['id']));
	}

}